﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EFong.ServicesInterface;
using EFong.BL;
using System.Xml.Linq;

namespace EFong.Services
{
    public class BaseService : IBaseService, IService
    {
        #region IBaseService 成员

        public Contract.ServiceResult<List<Contract.Currency>> GetAllCurrency()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<List<Contract.Currency>>(baseBL.GetAllCurrency());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.Currency>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.Currency>>(e); }
        }

        public Contract.ServiceResult<Contract.Currency> GetCNYCurrency()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<Contract.Currency>(baseBL.GetCNYCurrency());
            }
            catch (BusinessException be) { return this.Fail<Contract.Currency>(be); }
            catch (Exception e) { return this.Fail<Contract.Currency>(e); }
        }

        public Contract.ServiceResult UpdateExchangeRate(List<Contract.Currency> currencyList)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                baseBL.UpdateExchangeRate(currencyList);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<Contract.User> Login(string name, string password)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<Contract.User>(baseBL.Login(name, password));
            }
            catch (BusinessException be) { return this.Fail<Contract.User>(be); }
            catch (Exception e) { return this.Fail<Contract.User>(e); }
        }

        public Contract.ServiceResult<List<Contract.User>> GetAllUser()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<List<Contract.User>>(baseBL.GetAllUser());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.User>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.User>>(e); }
        }

        public Contract.ServiceResult<List<Contract.User>> GetEffUser()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<List<Contract.User>>(baseBL.GetEffUser());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.User>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.User>>(e); }
        }

        public Contract.ServiceResult NewUser(Contract.User user)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                baseBL.NewUser(user);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult ModifyUserPassword(string userName, string oldPassword, string newPassword)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                baseBL.ModifyUserPassword(userName, oldPassword, newPassword);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult UpdateUserList(List<Contract.User> userList)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                baseBL.UpdateUserList(userList);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<List<Contract.Role>> GetAllRole()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<List<Contract.Role>>(baseBL.GetAllRole());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.Role>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.Role>>(e); }
        }

        public Contract.ServiceResult NewRole(Contract.Role role)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                baseBL.NewRole(role);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult UpdateRoleList(List<Contract.Role> roleList)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                baseBL.UpdateRoleList(roleList);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<List<Contract.HotelLevel>> GetAllHotelLevel()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<List<Contract.HotelLevel>>(baseBL.GetAllHotelLevel());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.HotelLevel>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.HotelLevel>>(e); }
        }

        public Contract.ServiceResult<List<Contract.AuthorizedItem>> GetAllAuthorizedItem()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<List<Contract.AuthorizedItem>>(baseBL.GetAllAuthorizedItem());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.AuthorizedItem>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.AuthorizedItem>>(e); }
        }

        public Contract.ServiceResult<List<Contract.CustomerHotelIntergralRate>> GetOriginalHotelIntergralRateList()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<List<Contract.CustomerHotelIntergralRate>>(baseBL.GetOriginalHotelIntergralRateList());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.CustomerHotelIntergralRate>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.CustomerHotelIntergralRate>>(e); }
        }

        public Contract.ServiceResult<List<Contract.WebUser>> GetAvailableWebUserList()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<List<Contract.WebUser>>(baseBL.GetAvailableWebUserList());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.WebUser>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.WebUser>>(e); }
        }

        public Contract.ServiceResult<DateTime> GetDate()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<DateTime>(baseBL.GetDate());
            }
            catch (BusinessException be) { return this.Fail<DateTime>(be); }
            catch (Exception e)
            {
                return this.Fail<DateTime>(e);
            }
            
        }

        public Contract.ServiceResult ImportData(XElement data)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                baseBL.ImportData(data);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<XElement> ExportData(DateTime dateTime)
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<XElement>(baseBL.ExportData(dateTime));
            }
            catch (BusinessException be) { return this.Fail<XElement>(be); }
            catch (Exception e) { return this.Fail<XElement>(e); }
        }

        public Contract.ServiceResult<DateTime> GetLatestExportDate()
        {
            try
            {
                BaseBL baseBL = new BaseBL();
                return this.Return<DateTime>(baseBL.GetLatestExportDate());
            }
            catch (BusinessException be) { return this.Fail<DateTime>(be); }
            catch (Exception e) { return this.Fail<DateTime>(e); }
        }

        #endregion
    }
}